// pages/logmessage/logmessage.js
const app = getApp()
const net = app.globalData.net;
Page({

  data: {
    idcard: 0,
    real_name: '',
    idcard_frist: '',
    idcard_last: '',
    sex: 1,
    add_car: false,
    remo_car: false,
    hid:0,

  },
  onLoad: function(options) {
     this.setData({
       hid:options.hid,
     })
  },

  idcard(e) {
    this.setData({
      idcard: e.detail.value,
    })
  },
  real_name(e) {
    this.setData({
      real_name: e.detail.value,
    })
  },
  setsex() {
    if (this.data.sex) {
      this.setData({
        sex: 0
      })
    } else {
      this.setData({
        sex: 1
      })
    }
  },
  smrz() {
    console.log('real_name', this.data.real_name);
    console.log('idcard', this.data.idcard);
    wx.getStorage({
      key: 'uid',
      success: (res) => {
        wx.request({
          url: net + '/user/real',
          method: "POST",
          data: {
            uid: res.data,
            idcard: this.data.idcard,
            real_name: this.data.real_name,
            idcard_frist: this.data.idcard_frist,
            idcard_last: this.data.idcard_last,
            sex: this.data.sex,
          },
          success: (res) => {
            if (res.data.state) {
              console.log("实名成功")
              if(this.data.hid){
                wx.reLaunch({
                  url: `/pages/onlinesigning/onlinesigning?hid=${this.data.hid}`,
                })
              }else{
                wx.reLaunch({
                  url: `/pages/me/me`,
                })
              }
            } else {
              const info = res.data.info;
              wx.showModal({
                content: info,
                showCancel: false,
              })
            }
            console.log("实名认证下一步", res);

          }
        });

      },
    })

  },
  getfircar() {
    // 获取身份证正面照片
    wx.chooseImage({
      count: 1,
      success: (res) => {
        console.log("即将要上传的文件路径", res);
        wx.uploadFile({
          url: 'http://192.168.3.11:7001/user/upload',
          filePath: res.tempFilePaths[0],
          name: 'frist',
          success: (res) => {
            const ress = JSON.parse(res.data);
            this.setData({
              idcard_frist: ress.url,
            })
          }
        })
      }
    })
  },
  getlastcar() {
    // 获取身份证反面照片
    wx.chooseImage({
      count: 1,
      success: (res) => {
        console.log("即将要上传的文件路径", res);
        wx.uploadFile({
          url: 'http://192.168.3.11:7001/user/upload',
          filePath: res.tempFilePaths[0],
          name: 'frist',
          success: (res) => {
            const ress = JSON.parse(res.data);
            this.setData({
              idcard_last: ress.url,
            })
          }
        })
      }
    })
  },


  onReady: function() {

  },
  onShow: function() {

  },


  onHide: function() {

  },


  onUnload: function() {

  },


  onPullDownRefresh: function() {

  },


  onReachBottom: function() {

  },


  onShareAppMessage: function() {

  }
})